#ifndef ALLOCATOR_H
#define ALLOCATOR_H

#include "memory_pool.h"

namespace sgi_memo_pool{

// [错误1] 之前类名拼写错误，原为Alloctor，已修复为Allocator
class Allocator{

public:
    static void* allocate(size_t n){
        return MemoryPool::allocate(n);
    }
    static void deallocate(void* p,size_t n){
        return MemoryPool::deallocate(p,n);
    }
    static void* reallocate(void* p,size_t old_sz,size_t new_sz){
        return MemoryPool::reallocate(p,old_sz,new_sz);
    }

};   

// [错误2] 类名与测试代码不匹配，原为TypeAllocator，应为TypedAllocator
template <class T>
class TypedAllocator{
public:
    // [错误3] 之前有未定义变量n，已修复为使用sizeof(T)
    static T* allocate(){
        return static_cast<T*>(Allocator::allocate(sizeof(T)));
    }

    static T* allocate(size_t n){
        return static_cast<T*>(Allocator::allocate(n* sizeof(T)));
    }

    static void deallocate(T* p){
        Allocator::deallocate(p,sizeof(T));
    }

    static void deallocate(T* p,size_t n){
        Allocator::deallocate(p,n*sizeof(T));
    }

    static void construct(T* p,const T& value){
        new(p) T(value);
    }

    // [错误4] 方法名拼写错误，原为destory，已修复为destroy
    // [错误4] 方法名拼写错误，原为destory，已修复为destroy
    static void destroy(T* p){
        p->~T();
    }
};


}

#endif